package itsm.isperp.job;

import itsm.isperp.module.service.app.AppDepartmentService;
import itsm.isperp.module.service.app.AppUserService;

import javax.naming.NamingException;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 
 * ad域数据同步
 * 
 * 
 * @author lizx
 * @date 2014-09-07
 * @since 1.0
 * 
 */
@Service
public class LdapDataSyncJob implements Job {

	public static final Logger logger = LoggerFactory
			.getLogger(LdapDataSyncJob.class);

	@Autowired
	AppDepartmentService appDepartmentService;
	@Autowired
	AppUserService appUserService;

	@Override
	public void execute(JobExecutionContext context)
			throws JobExecutionException {

		try {
			appDepartmentService.syncUnitData();
		} catch (NamingException e) {
			logger.error("同步组织失败，原因是：" + e.getMessage(), e);
		}
		try {
			appUserService.syncUserData();
		} catch (NamingException e) {
			logger.error("同步组织用户失败，原因是：" + e.getMessage(), e);
		}

		logger.info("ldap数据同步成功！");

	}

}
